This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 21, 2011, 10:29 PM
10 Posts

Putting Results of fetch into dijit.Tree

  • Category: Dojo and Client Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: dijit dojo lazy-load tree
  • Replies: 0
I have used the last example on this page of the dojo toolkit http://dojotoolkit.org/reference-guide/quickstart/data/usingdatastores/lazyloading.html to load items on demand.  I can get the data from the store to display as straight text if I create a field for it, however I cannot get it to populate my dijit tree.  If anybody has any idea what I need to do to get this to happen, it would be wonderful.  Here's the source code from my custom control:
 
 <?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" dojoParseOnLoad="true"
    dojoTheme="true">
    
    
    <xp:this.resources>
        <xp:dojoModule name="dojo.data.ItemFileReadStore"></xp:dojoModule>
        <xp:dojoModule name="dijit.tree.ForestStoreModel"></xp:dojoModule>
        <xp:dojoModule name="dijit.Tree"></xp:dojoModule>
        <xp:dojoModule name="dijit.layout.BorderContainer"></xp:dojoModule>
        <xp:dojoModule name="dojox.layout.ContentPane"></xp:dojoModule>
    </xp:this.resources>
    
    <xp:this.beforePageLoad><![CDATA[#{javascript:if(sessionScope.sessionParm == null) {
    sessionScope.sessionParm = (@ClientType()=="Notes" ? "?SessionID="+facesContext.getExternalContext().getRequest().getSession().getId() : "");
}}]]></xp:this.beforePageLoad>
    
     <!--     <div  id="preloader"></div>-->
<div dojoType="dijit.layout.BorderContainer" id="BC"
        design="sidebar" gutters="true" liveSplitters="true" style="width:100%;height:100%">

        <div dojoType="dijit.layout.ContentPane" executeScripts="true" id="CPone" splitter="true" preload="true"
            region="leading" style="width: 230px;">

            <img src="oscar.gif" border="0" />

            <!--  begin tree -->  
     <script>
            dojo.require("dojo.data.ItemFileReadStore");

           <!--  This function performs some basic dojo initialization. In this case it connects the button
            //onClick to a function which invokes the fetch(). The fetch function queries for all items
            //and provides callbacks to use for completion of data retrieval or reporting of errors.-->
              function init() {
               var store = new dojo.data.ItemFileReadStore({url: "nav.json "});
 
        <![CDATA[  function gotContinents(items, request){

                  <!-- Cycle over all the matches.-->
                      for(var i = 0; i < items.length; i++){
                        var item = items[i];
                         <!--  Cycle over all the attributes.-->
                        var attributes = store.getAttributes(item);
                        for (var j = 0; j < attributes.length; j++){
                              <!-- Assume all attributes are multi-valued and loop over the values ... -->
                              var values = store.getValues(item, attributes[j]);
                              for(var k = 0; k < values.length; k++){
                                var value = values[k];

                                if(store.isItem(value)){
                                      <!-- Test to see if the items data is fully loaded or needs to be demand-loaded in (the item in question is just a stub). -->
                                      if(store.isItemLoaded(value)){  
                                      }else{
                                           <!-- Asynchronously load in the child item using the stub data to get the real data. -->
                                            var lazyLoadComplete = function(item){
                                        }
                                        store.loadItem({item: value, onItem: lazyLoadComplete});
                                      }
                                    }else{                                  
                                  }
                              }
                            }
                         }
                    }
                
                 ]]>
 
                  <!-- Callback for if the lookup fails. -->
                      function fetchFailed(error, request) {
                        console.log(error);
                        alert("lookup failed.");
                    }

                    <!-- Fetch the data. -->
                    store.fetch({
                   onError: fetchFailed,
                    query: {type: "cat"},
                    onComplete: gotContinents
                     });
           }
            <!-- Set the init function to run when dojo loading and page parsing has completed.-->
            dojo.addOnLoad(init);        
       </script>    
       
                   <div dojoType="dijit.tree.ForestStoreModel" store="store" rootId="navRoot" labelAttr="name"  rootLabel="OSCAR" childrenAttrs="children">
                </div>
       
       <div dojoType="dijit.Tree" model="navModel" openOnClick="true" showRoot="false">
                <script type="dojo/method" event="onClick"
                    args="item">
                    <!--  item id is the xsp page name -->
                    var pageName = navStore.getValue(item, "id");

                    <!--   navigate to xsp page -->
                    window.location.href = pageName + getSessionParm();
                </script>

                <!-- We need to highlight (focus) the node which matches the current page. -->
                <!-- The ideal time to do this is after the tree has finished loading.  However... -->
                <!-- Dojo 1.3 does not have an onLoad event for the tree widget, -->
                <!-- so we use the onOpen event which fires when a node is expanded. -->
                <!-- This works because the tree will auto-expand itself to its last -->
                <!-- expand state on load. -->
                <script type="dojo/method" event="onOpen" args="item">
                    <!-- get current xpage name (this should match a node in the tree) -->
                    var currentPage = getCurrentXPage();

                    <!-- focus the node that matches the current page -->
                    var node = navTree._itemNodesMap[currentPage]; if
                    (node) { navTree.focusNode(node); }
                </script>
            </div>
            <!--  end tree -->      
            </div>
            
   <div dojoType="dijit.layout.ContentPane" id="CPtwo" preload="true"
            region="center">

            <xp:callback facetName="facet_1" id="callback1"></xp:callback>
          </div>

        <xp:scriptBlock id="scriptBlock1">
            <xp:this.value><![CDATA[function getCurrentXPage() {
        var page = "#{javascript:view.getPageName()}";
        return (page.length > 1 ? page.substr(1) : page);
}

function getSessionParm() {

        return "#{sessionScope.sessionParm}";
}
]]></xp:this.value>
        </xp:scriptBlock>
         
                      
            </div>    
        
    </xp:view>

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal